<?php
namespace app\index\controller;
use think\Controller;
use think\Log;
use Payment\Common\PayException;
use Payment\Client\Notify;

date_default_timezone_set('Asia/Shanghai');
//use app\common\service\Payment;

class Snotify extends Controller
{
    public function index(){

        $type=input('type','');

        if (stripos($type, 'ali') !== false) {
           $config = [
            'use_sandbox'               => true,// 是否使用沙盒模式
            'partner'                   => '2088102172166835',
            'app_id'                    => '2016082000291972',
            'sign_type'                 => 'RSA2',// RSA  RSA2
            // 可以填写文件路径，或者密钥字符串  当前字符串是 rsa2 的支付宝公钥(开放平台获取)
            'ali_public_key'            => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3jOsgmVIlk2lYm47AskKxmL3RAM92IYZHIpH3uja8elQyZpMQqX28Lk2kI4xrJrrVgBpnAVkHu4xAcz1iczqaDVXNKgcBY6GFn3bDh3gZTqe0C4QGx6L8S2PbVd9WkhkKvwcJMYr94GemhztlgE+RDYeQ0ZI23YgLcA/LvZw+pU9V7bnKjYRlYj+FbxCZSGPN3E9JNX2caAcQjJmxnPKolE7IS6HZAFB8/jKBF0f+eWE3FcAG1YVq6qFOWtCqt0sasNddIFLReZX9yqZCQp+79LKP2kmkDgMiBQof68UtZPG4QrMtZrKdVnS07XMMgrCJbj5uCLXafmrFh7xLw4gcQIDAQAB',

            // 可以填写文件路径，或者密钥字符串  我的沙箱模式，rsa与rsa2的私钥相同，为了方便测试
            'rsa_private_key'           => 'MIIEowIBAAKCAQEAzTo2yTfAVGynZUg/ew37ItbtPLPDHhHcn8irhz8edYpzkxto
KLUpy7qA27moHhEtsPLCOPnySvB1BHzbLwZsVMPIKqT+kUbPBO6rm1QJVfK3JWUT
TVXr8oU8vhCjcaciwaBoZXAw1KMeVXBWADXf3nHdh+xNXMvTFPJKtg2kDDfKovoJ
8ZPD8/Wsh27yjJWEFDofwnpyD0ILHppwxzRe11PNhm8bH01JI0n1648YVOLVB653
mcuZ2/N8XYw3f4qYYDS3NUF8aZ9eOF72+4uvkIX8USb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NHSVdmRuJ6czvNH10lmKNTiWISmeNrAP4TPOs6W+w3y8DydnhzD/sYwnfM+e
cTnnoQKBgDsk3Yh8l1J1IFRrXFyKkThIH3u1OEXKqbznC13zuasVsa/YnSCb5Oqa
Nyuud+zySPu9dK/wzOBj/FyCPEE1gs7rNl6oORyBfcb2lLmi1OlTRKuRrssjzLUM
fZLB7ubWY5N/S+2NLivLnrqgSSNHFOogLiupAZJ1m5OUHQL84pxx',
            'limit_pay'                 => [
                //'balance',// 余额
                //'moneyFund',// 余额宝
                //'debitCardExpress',// 	借记卡快捷
                //'creditCard',//信用卡
                //'creditCardExpress',// 信用卡快捷
                //'creditCardCartoon',//信用卡卡通
                //'credit_group',// 信用支付类型（包含信用卡卡通、信用卡快捷、花呗、花呗分期）
            ],// 用户不可用指定渠道支付当有多个渠道时用“,”分隔

            // 与业务相关参数
            'notify_url'        => 'http://chongzhi.ruanduo.com/index/snotify/index/type/ali_charge',
            'return_url'      => 'http://chongzhi.ruanduo.com/index/index/return_url',// 如果是h5支付，可以设置该值，返回到指定页面

            'return_raw'                => true,// 在处理回调时，是否直接返回原始数据，默认为 true
        ];
        } elseif (stripos($type, 'wx') !== false) {
            $config=  [
                'use_sandbox'       => false,// 是否使用 微信支付仿真测试系统
                'app_id'            => 'wx138f75e84b948401',  // 公众账号ID
                'mch_id'            => '1487979432',// 商户id
                'md5_key'           => 'dfsfsdfsdfsdfsdfsdfsdfasdfsdfsdf',// md5 秘钥
                'app_cert_pem'      => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wx' . DIRECTORY_SEPARATOR .  'pem' . DIRECTORY_SEPARATOR . 'weixin_app_cert.pem',
                'app_key_pem'       => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wx' . DIRECTORY_SEPARATOR .  'pem' . DIRECTORY_SEPARATOR . 'weixin_app_key.pem',
                'sign_type'         => 'MD5',// MD5  HMAC-SHA256
                'limit_pay'         => [
                ],// 指定不能使用信用卡支付   不传入，则均可使用
                'fee_type'          => 'CNY',// 货币类型  当前仅支持该字段
                'notify_url'        => 'http://chongzhi.ruanduo.com/index/snotify/index/type/wx_charge',
                'redirect_url'      => 'http://chongzhi.ruanduo.com/index/index/return_url',// 如果是h5支付，可以设置该值，返回到指定页面
                'return_raw'        => true,// 在处理回调时，是否直接返回原始数据，默认为true
            ];
        } else {
           // $config = $cmbConfig;
        }

        try {
            $callback = new PayNotify();
            //$retData = Notify::getNotifyData($type, $config);// 获取第三方的原始数据，未进行签名检查
            $ret = Notify::run($type, $config, $callback);// 处理回调，内部进行了签名检查
        } catch (PayException $e) {
            Log::error($e->errorMessage());
            echo $e->errorMessage();
            exit;
        }
        Log::info(var_export($ret,true));
        var_dump($ret);
        exit;

    }




}



